﻿using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Timers;

namespace DZPK
{
    public class PlayEngine
    {
        public PlayerManager PlayerManagerInstance;
        public TableManager TableManagerInstance;
        public Timer PlayerHeartBeatTimer;

        private PlayEngine()
        {
            PlayerManagerInstance = new PlayerManager();
            TableManagerInstance = new TableManager();

            PlayerHeartBeatTimer = new Timer();
            PlayerHeartBeatTimer.Interval = 2000;  // 2s
            PlayerHeartBeatTimer.Elapsed += new ElapsedEventHandler(HeartBeat_Elapsed);
            PlayerHeartBeatTimer.Start();
        }

        private static PlayEngine playEngin = null;

        public static PlayEngine GetPlayEnginInstance()
        {
            if (playEngin == null)
            {
                playEngin = new PlayEngine();
            }

            return playEngin;
        }

        private void HeartBeat_Elapsed(object sender, ElapsedEventArgs e)
        {
            PlayerManagerInstance.MarkPlayerHeartBeatToServer();
        }

        public void PlayerSitToTable(Player player, int seatID, int tableID)
        {
            
        }

        public void PlayerStand(Player player, int seatID, int tableID)
        {
            
        }

        public Player GetPlayerFromMid(int mid)
        {
            return null;
        }

        public ServerInfo GetTableIpPortFromTableIndex(int index)
        {
            return TableManagerInstance.GetTableIpPortFromTableIndex(index);
        }
    }
}
